import request from '../../utils/request'
Page({
    data:{
        bannerList:[], //轮播图数据
        recommendList:[],   //推荐音乐数据
        rankingList:[]  //排行榜数据
    },

    async onLoad(){
        const bannerData = await request('/banner',{type:2})
        const recommendData = await request('/personalized',{limit:30})
        /**
         * 需要根据idx的值获取对应的数据
         * idx的取值范围是0-20，我们需要0-4
         * 需要发送5次请求
         */
        let index = 0;
        const topList = [];
        while(index < 5){
            const topListData = await request('/top/list',{idx:index++});
            const topListItem = {
                name:topListData.playlist.name,
                tracks:topListData.playlist.tracks.slice(0,3)
            }
            topList.push(topListItem)
            this.setData({
                rankingList:topList
            })
        }
        this.setData({   
            bannerList:bannerData.banners,
            recommendList:recommendData.result,
        })
    },
    
    onShow(){

    },

    onReady(){

    }
})